package study.async.springboot.support.async;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Slf4j
@Configuration

public class AsyncConfig {

    @Bean("executor")
    public Executor executor1() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //thread name prefix
        executor.setThreadNamePrefix("test-schedule-");
        //core thread size
        executor.setCorePoolSize(15);
        //max thread size
        executor.setMaxPoolSize(20);
        //queue size
        executor.setQueueCapacity(0);
        //reject handler
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return executor;
    }
}
